package br.edu.sistemaacademico.command;

import java.io.Serializable;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.sql.SQLException;
import java.util.List;

import br.edu.sistemaacademico.builder.*;
import br.edu.sistemaacademico.pojo.*;

public class CommandDisciplina extends UnicastRemoteObject implements Command, Serializable{
	DisciplinaDAO disciplinaDao = new DisciplinaDAO();
	protected CommandDisciplina() throws RemoteException {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public boolean alterar(Object o) throws RemoteException {
		Disciplina disciplina = (Disciplina) o;
		try {
			disciplinaDao.alterar(disciplina);
			return true;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public Object carregaObjeto(String condicao, String tabelasAdd)
			throws RemoteException {

		try {
			return disciplinaDao.getObject(condicao, tabelasAdd);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public List<Object> carregar(String condicao, String tabelasAdd)
			throws RemoteException {
		return disciplinaDao.getAll(condicao, tabelasAdd, "nome");
	}

	@Override
	public boolean deletar(Object o) throws RemoteException {
		Disciplina disciplina = (Disciplina) o;
		disciplinaDao.deletar(disciplina);
		return true;
	}

	@Override
	public List<Object> getCampos() throws RemoteException {
		return disciplinaDao.getCampos();
	}

	@Override
	public boolean gravar(Object o) throws RemoteException {
		Disciplina disciplina = (Disciplina) o;
		try {
			disciplinaDao.gravar(disciplina);
			return true;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}

}
